package DataBaseTest;

import java.util.ArrayList;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import DataBase.DB_Factory;
import DataBaseInterface.ManagerServerInterface;
import Po.Manager;
import Po.Message;
import Po.Result;

public class ManagerServerTest {

	ManagerServerInterface test ;
	
	@Before
	public void setUp() throws Exception {
		test = DB_Factory.getManagerServerDB(); 
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public final void testGetManager() {
		ArrayList<Manager> l = test.getSaleManager();
		Assert.assertTrue(l.size() == 2);
		Assert.assertTrue(l.get(0).name.equals("whk"));
	}
	
	@Test
	public final void testAddGM() {
		Message m = test.addGeneralManager(new Manager("www", "123456"));
		Assert.assertTrue(m.result == Result.Success);
	}
	
	@Test
	public final void testAddSM() {
		Message m = test.addSaleManager(new Manager("whh", "111"));
		Assert.assertTrue(m.result == Result.Success);
	}
	
	@Test
	public final void testModifySM() {
		Message m = test.modifySaleManager(new Manager("zjq", "111111"));
		Assert.assertTrue(m.result == Result.Success);
	}
	
	@Test
	public final void testModifyGM() {
		Message m = test.modifyGeneralManager(new Manager("whk", "111111"));
		Assert.assertTrue(m.result == Result.Success);
	}
	
	@Test
	public final void testDelSM() {
		Message m = test.deleteSaleManager(new Manager("whh", "111"));
		Assert.assertTrue(m.result == Result.Success);
	}
	
	@Test
	public final void testDelGM() {
		Message m = test.deleteGeneralManager(new Manager("www", "123456"));
		Assert.assertTrue(m.result == Result.Success);
	}
	
	@Test
	public final void testGmLogin() {
		Manager m = test.GeneralManagerLogin(new Manager("whk", "111111"));
		Assert.assertTrue(m.name.equals("whk"));
		Assert.assertTrue(m.password.equals("111111"));
	}
	
	@Test
	public final void testSmLogin() {
		Manager m = test.SaleManagerLogin(new Manager("zjq", "111111"));
		Assert.assertTrue(m.name.equals("zjq"));
		Assert.assertTrue(m.password.equals("111111"));
	}
	
}
